﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class AwardIssued : System.Web.UI.Page
{
    PagedDataSource objPds = new PagedDataSource();

    protected void Page_Load(object sender, EventArgs e)
    {
        MasterPage master = this.Master as MasterPage;
        master.BodyId = "awardissued";
            ItemsGet();
        
    }
    private void ItemsGet()
    {

        CompetitionDAO comDAO = new CompetitionDAO();
        AwardDAO awardDAO = new AwardDAO();
        AwardIssuedDAO awardissuedDAO = new AwardIssuedDAO();

        IList<CompetitionInfo> listCompet = comDAO.SelectPrevious();

        objPds = new PagedDataSource();
        objPds.DataSource = listCompet;
        objPds.AllowPaging = true;
        objPds.PageSize = 3;

        try
        {
            objPds.CurrentPageIndex = Int32.Parse(Request["Page"].ToString());
        }
        catch (Exception ex)
        {
            objPds.CurrentPageIndex = 0;
        }

        lblCurrentPage.Text = "Page " + (objPds.CurrentPageIndex + 1).ToString() + " of "
            + objPds.PageCount.ToString();

        if (!objPds.IsFirstPage)
            cmdNext.Enabled = !objPds.IsLastPage;
          
        if (!objPds.IsLastPage)
            cmdPrev.Enabled = !objPds.IsFirstPage;
         

        dtl_Previous.DataSource = objPds;
        dtl_Previous.DataBind();

        if (dtl_Previous.Items.Count > 0)
        {
            foreach (DataListItem item in dtl_Previous.Items)
            {
                Label competitionID = item.FindControl("lblCompetitionID") as Label;
                int competID = Convert.ToInt32(competitionID.Text);


                GridView grv = (GridView)item.FindControl("grv_AwardIssued");
                grv.DataSource = awardissuedDAO.Get_Award_Issued(competID);
                grv.DataBind();


            }
        }

    }

    protected void cmdPrev_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (objPds.CurrentPageIndex - 1));
    }
    protected void cmdNext_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (objPds.CurrentPageIndex + 1));
    }
}